<template>
	<view>
		<wrapBgImg />

		<navigationBar navigationTitle="申请合伙人" />

		<view class="wrap safe-area flex column align-center">
			<view class="wrap-white-bg">
				<block v-for="(item, index) in list" :key="index">
					<rowOCR
						v-if="item.type === 'ocr' && item.direct === 'row'"
						:item="item"
						v-model="dataInfo[item.key]"
						@ocrData="onOcrData"
					/>

					<rowInput
						v-else-if="
							item.type === 'input' &&
							item.direct === 'row' &&
							(item.isShow === undefined ? true : item.isShow)
						"
						:item="item"
						v-model="dataInfo[item.key]"
					/>

					<rowGroup
						v-else-if="item.type === 'group' && item.direct === 'row'"
						:item="item"
						v-model="dataInfo[item.key]"
					/>

					<areaList v-else-if="item.type === 'area'" :item="item" v-model="dataInfo[item.key]" />

					<rowChoose
						v-else-if="item.type === 'choose' && item.direct === 'row'"
						:item="item"
						v-model="dataInfo[item.key]"
					/>
				</block>
			</view>

			<view class="sure-btn theme-gradient-btn f-34" @click="onSubmit">提交</view>
		</view>
	</view>
</template>

<script>
	import { applyPartner } from "@/API/partner.js";

	import wrapBgImg from "@/components/navigationBar/bgImg.vue";
	import navigationBar from "@/components/navigationBar/navigationBar.vue";
	import rowOCR from "@/components/form/rowOCR.vue";
	import rowInput from "@/components/form/rowInput.vue";
	import rowGroup from "@/components/form/rowGroup.vue";
	import areaList from "@/components/form/areaList.vue";
	import rowChoose from "@/components/form/rowChoose.vue";
	export default {
		components: {
			wrapBgImg,
			navigationBar,
			rowOCR,
			rowInput,
			rowGroup,
			areaList,
			rowChoose,
		},
		data() {
			return {
				dataInfo: {
					name: "", //姓名
					mobile: "", //手机号
					id_card: "", //身份证号
					inviter: "1", //是否有推荐人 1有 0无
					identity_type: "1", //身份类型:1=个人(天使)合伙人,2=商户合伙人,3=城市服务商
					inviter_mobile: "", //推荐人手机号
					area: "", //申请区域
					port_fee: "", //端口费
				},
				
				identityList: [{ id: "1", title: "焕焕伙伴"}], //身份列表
			};
		},
		computed: {
			list() {
				return [
					{
						title: "电话",
						require: true,
						type: "input",
						key: "mobile",
						place: "请输入电话",
						mode: "tel",
						maxlength: 11,
						direct: "row",
						tips: "请输入电话",
					},
					{
						title: "身份证",
						require: true,
						type: "ocr",
						key: "id_card",
						mode: "idcard",
						maxlength: 18,
						direct: "row",
						place: "请识别/输入身份证号",
						tips: "请识别/输入身份证号",
					},
					{
						title: "姓名",
						require: true,
						type: "input",
						key: "name",
						place: "请输入姓名",
						mode: "text",
						maxlength: 100,
						direct: "row",
						tips: "请输入姓名",
					},
					{
						title: "申请区域",
						require: true,
						type: "area",
						key: "area",
						tips: "请选择申请区域",
					},
					{
						title: "是否有推荐人",
						require: true,
						type: "group",
						direct: "row",
						key: "inviter",
						tips: "请选择是否有推荐人",
						list: [
							{
								id: "1",
								title: "有",
							},
							{
								id: "0",
								title: "无",
							},
						],
					},
					{
						title: "推荐人手机号",
						require: true,
						type: "input",
						key: "inviter_mobile",
						place: "请输入推荐人手机号",
						mode: "tel",
						maxlength: 11,
						direct: "row",
						tips: "请输入推荐人手机号",
						isShow: this.dataInfo.inviter === "1",
					},
					{
						title: "端口费",
						require: true,
						type: "input",
						key: "port_fee",
						place: "请输入端口费",
						mode: "digit",
						maxlength: 8,
						direct: "row",
						tips: "请输入端口费",
						isShow: this.dataInfo.identity_type !== "3",
						disabled: true,
					},
					{
						title: "身份类型",
						require: true,
						type: "choose",
						key: "identity_type",
						mode: "selector",
						direct: "row",
						place: "请选择身份类型",
						rangeKey: "title",
						list: this.identityList,
						tips: "请选择身份类型",
						isArrow: true,
					},
				];
			},
		},
		onLoad() {
			this.dataInfo.port_fee = this.$stoarge.getConfigData().partner_portfee;
			
			this.$commonNetwork.getUserIdenInfoData(res => {
				if (res.code == 1) {
					this.identityList = [{ id: "1", title: "个人焕焕伙伴"}];
				} else {
					this.identityList = [{ id: "1", title: "个人焕焕伙伴"}, { id: "1", title: "商户焕焕伙伴"}, { id: "3", title: "城市运营服务商",}];
				}
			})
		},
		methods: {
			/**
			 * ocr识别
			 */
			onOcrData(res) {
				this.dataInfo.name = res.Name;
				this.dataInfo.id_card = res.IDNumber;
			},
			/**
			 * 提交
			 */
			onSubmit() {
				if (this.$filters.judgeFormData(this.list, this.dataInfo)) {
					let obj = this.dataInfo;
					
					this.$throttle(() => {
						wx.login({
							success: (loginRes) => {
								obj.code = loginRes.code;
								applyPartner(obj).then((res) => {
									if (res.data === null) {
										this.$st.success("申请成功", () => {
											uni.navigateBack();
										});
									} else {
										this.$filters.onPayFunction(res.data, (res) => {
											if (res === 1) {
												uni.navigateBack();
											}
										});
									}
								})
							},
						});
					})
					
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "@/css/publish.css";
</style>
